import {
  wxRequest
} from '../../../utils/server.js';
const _wxRequest = new wxRequest();
const app = getApp()
Page({


  data: {
    imgUrl: app.globalData.imgUrl,
    uploadUrl: wx.getStorageSync('uploadUrl'),
    list: [],
    pageNo: 1,
    assessStatistics: wx.getStorageSync('assessStatistics'),
    gdsId: ''
  },

  onLoad: function(options) {
    if (options.gdsId) {
      this.setData({
        gdsId: options.gdsId,
        type: options.type || ''
      })

    }
  },

  onShow: function() {
    this.getlist()
  },

  onHide: function() {
    wx.removeStorageSync('assessStatistics')
  },
  onUnload: function() {
    wx.removeStorageSync('assessStatistics')
  },

  getlist: function() {
    _wxRequest.wxAjax({
      url: app.globalData.apiUrl + '/odr/assess/list?gdsId=' + this.data.gdsId + '&type='+this.data.type+ '&pageNo=' + this.data.pageNo,
      method: 'POST'
    }, (res) => {
      let list = res.list;
      if (this.data.pageNo !== 1) {
        list = this.data.list.concat(list);
      }
      list.map(item => {
        item.imgJson = JSON.parse(item.imgJson);
        var avatar = item.avatar
        if (avatar && avatar.indexOf('https') != 0) {
          item.avatar = this.data.uploadUrl + item.avatar
        } 
      })

      this.setData({
        list: list,
        pageNo: res.page.pageNo,
        hasNextPage: res.page.hasNextPage,
      });
    })
  },

  //触底时，加载更多
  onReachBottom: function() {
    if (this.data.hasNextPage) {
      this.setData({
        pageNo: this.data.pageNo + 1
      });
      this.getlist();
    }
  },


  typeChange:function(e){
    var type = e.detail;
    this.setData({type})
    this.getlist()
  }


})